﻿#ifndef __SS_WSPP_CLIENT_NETWORK_H__
#define __SS_WSPP_CLIENT_NETWORK_H__
#include "ssWsppBase.h"
#include <websocketpp/config/asio_no_tls_client.hpp>
#include <websocketpp/client.hpp>

using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;

namespace StarSeeker
{

typedef websocketpp::client<websocketpp::config::asio_client> client;
typedef websocketpp::config::asio_client::message_type::ptr message_ptr;

class ssWsppClientNetwork : public ssWsppBase
{
public:
	ssWsppClientNetwork();
	~ssWsppClientNetwork();
	//启动网络服务
	bool StartNetWork(const char* uri);
	//停止网络服务
	void StopNetWork();
	//创建连接
	void CreateConnect();
	//关闭连接
	void DoCloseSocket(u32 sessionId);
	//发送数据
	void DoSendData(u32 sessionId, const char* buf, u32 len);
private:
	//处理连接关闭
	void HandleClose(u32 sessionId);
	//处理发送
	void HandleSend(u32 sessionId, const char* buf, u32 len);
	//处理创建
	void HandleCreate();
	//删除session对象
	void DeleteSession(websocketpp::connection_hdl hdl);

	//websocketpp的回调函数
	void OnMessage(client* s, websocketpp::connection_hdl hdl, message_ptr msg);
	//void OnHttp(server* s, websocketpp::connection_hdl hdl);
	void OnSocketInit(websocketpp::connection_hdl hdl, asio::ip::tcp::socket & s);
	void OnFail(websocketpp::connection_hdl hdl);
	void OnClose(websocketpp::connection_hdl hdl);
	void OnOpen(websocketpp::connection_hdl hdl);


	client					m_echoServer;
	std::string				m_uri;
};

}
#endif
